package com.shilan.administrator.qintfm.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;

import com.shilan.administrator.qintfm.R;
import com.shilan.administrator.qintfm.fragment.tabhostFragment.DownLoadFragment;
import com.shilan.administrator.qintfm.fragment.tabhostFragment.FoundFragment;
import com.shilan.administrator.qintfm.fragment.tabhostFragment.MineFragment;

/**
 * Created by dllo on 16/1/14.
 */
public class MainFragment extends Fragment {

    private TabHost tabHost;
    private android.support.v4.app.FragmentManager fragmentManager;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.frgament_main,null);
        tabHost = (TabHost) view.findViewById(android.R.id.tabhost);
        tabHost.setup();//初始化
        init();
        initView();
        return view;
    }



    private void init() {
        TabHost.TabSpec tab1 = tabHost.newTabSpec("我的");
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.tab_mine, null);
        tab1.setIndicator(view);
        //绑定占位fragment
        tab1.setContent(R.id.mineView);
        tabHost.addTab(tab1);

        TabHost.TabSpec tab2 = tabHost.newTabSpec("发现");
        View view2 = LayoutInflater.from(getActivity()).inflate(R.layout.tab_found,null);
        tab2.setIndicator(view2);
        tab2.setContent(R.id.foundView);
        tabHost.addTab(tab2);

        TabHost.TabSpec tab3 = tabHost.newTabSpec("下载");
        View view3 = LayoutInflater.from(getActivity()).inflate(R.layout.tab_download,null);
        tab3.setIndicator(view3);
        tab3.setContent(R.id.downloadView);
        tabHost.addTab(tab3);
    }
    private void initView() {

        fragmentManager = getActivity().getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.replace(R.id.mineView,new MineFragment());
        ft.replace(R.id.foundView,new FoundFragment());
        ft.replace(R.id.downloadView, new DownLoadFragment());
        ft.commit();
    }
}
